﻿// -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Tests
//  File name:	TestGeneric.cs
//  Developer:	Igor Solomatov
//  Created:	20.12.2014
// 
// -------------------- iSharePoint -------------------- //

using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Smart.Tests
{
	[TestClass]
	public class TestGeneric
	{
		[TestMethod]
		public void TestInterlocked()
		{
			var x = 0;

			// Disposable is based on this pattern

			Assert.AreEqual(0, Interlocked.CompareExchange(ref x, 1, 0));
			Assert.AreEqual(1, Interlocked.CompareExchange(ref x, 1, 0));
			Assert.AreEqual(1, Interlocked.CompareExchange(ref x, 1, 0));
		}

		[TestMethod]
		public void TestUnchecked()
		{
			// Settings cache is based on this pattern
			unchecked
			{
				var x = int.MaxValue;

				Assert.AreEqual(int.MaxValue, x);

				x += 1000;

				Assert.AreEqual(1000, x - int.MaxValue);

				x += 10;

				Assert.IsTrue(x - int.MaxValue > 1009);
				Assert.IsTrue(x - int.MaxValue == 1010);
				Assert.IsTrue(x - int.MaxValue < 1011);
			}
		}
	}
}